let maxBag = 8;
let bag = [];
// 物品体积和价值
let things = [[2,3], [3,4], [4,5], [5,6]];
let weight = [0, 2, 3, 4, 5];
let value = [0, 3, 4, 5, 8];
let bagArray = new Array(maxBag + 1);
let finalArr = {};//[[], [], [], []];

// 构建二维数组
/**
 * 选择物品i
 */
function subset(num, maxBag) {
  if(num <= 0) {
    return 0;
  }
  if(maxBag <= 0) {
    return 0;
  }
  if(weight[num] > maxBag) {
    return 0;
  }
  return finalArr[`${num},${maxBag}`] = Math.max(subset(num - 1, maxBag), subset(num - 1, maxBag - weight[num]) + value[num]);
}

console.log(subset(4, 8))                                                         
console.log(finalArr)